package com.sl.core.domain.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.sl.core.utils.JsonMap;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Getter
@Setter
public class TransformationStep extends JsonMap {

    private String name;

    private String type;

    private String distribute;

    private String copies;

    private String dynamicInputFlag;

    private TransformationStepPartitioning partitioning;

    @JsonProperty("GUI")
    private TransformationStepGUI gui;

    public static TransformationStep basic(String name, String type, String dynamicInputFlag, Map<String, Object> extParamMap) {
        TransformationStep transformationStep = new TransformationStep();
        transformationStep.setName(name);
        transformationStep.setType(type);
        transformationStep.setDistribute("N");
        transformationStep.setCopies("1");
        transformationStep.setDynamicInputFlag(dynamicInputFlag);
        transformationStep.setPartitioning(TransformationStepPartitioning.basic());
//        transformationStep.setExtParamMap(extParamMap);
        transformationStep.putAll(extParamMap);

        TransformationStepGUI transformationStepGUI = TransformationStepGUI.basic("0", "0", new HashMap<>());
        transformationStep.setGui(transformationStepGUI);

        transformationStep.build();
        return transformationStep;
    }

    public static void build(List<TransformationStep> stepList) {
        if (null == stepList) {
            return;
        }
        for (TransformationStep transformationStep : stepList) {
            Optional.ofNullable(transformationStep.getGui()).ifPresent(TransformationStepGUI::build);
            transformationStep.build();
        }
    }
}
